package com.workcell.workdata.xthings.controller;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.workcell.workdata.common.core.constant.SecurityConstants;
import com.workcell.workdata.common.core.util.R;
import com.workcell.workdata.common.security.annotation.Inner;
import com.workcell.workdata.xthings.api.feign.RemoteFormDataService;
import com.workcell.workdata.xthings.dto.fd.SavaCommentVo;
import com.workcell.workdata.xthings.service.XiaoSiMapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@RequiredArgsConstructor
@RequestMapping("/xiaosiMap")
@Api(value = "XiaoSiMapController", tags = "小思地图")
public class XiaoSiMapController {
    private final RemoteFormDataService remoteFormDataService;
    private final XiaoSiMapService xiaoSiMapService;

    @Inner(value = false)
    @ApiOperation(value = "异常管控系统列表", notes = "异常管控系统列表")
    @PostMapping("/abnormalList")
    public R abnormalList(@RequestBody Map<String, Object> dto) {
        Assert.isTrue(MapUtil.isNotEmpty(dto), "参数不能为空");
        return remoteFormDataService.abnormalList(dto, SecurityConstants.FROM_IN);
    }

    @Inner(value = false)
    @ApiOperation(value = "异常管控系统区域计数", notes = "异常管控系统区域计数")
    @GetMapping("/areaCount/{templateId}")
    public R areaCount(@PathVariable Long templateId) {
        Assert.isTrue(ObjectUtil.isNotEmpty(templateId), "模版不能为空");
        return remoteFormDataService.areaCount(templateId, SecurityConstants.FROM_IN);
    }

    @ApiOperation("保存评论")
    @PostMapping("/savaComment")
    public R comment(@RequestBody SavaCommentVo savaCommentVo) {
        xiaoSiMapService.saveComment(savaCommentVo);
        return R.ok();
    }

    @ApiOperation("根据异常申报Id查询评论列表")
    @GetMapping("/listComentById")
    public R CommentList(String id, Integer current, Integer size) {
        return xiaoSiMapService.commentList(id, current, size);
    }

}
